cc.Class({
    extends: cc.Component,

    properties: {
        txtScore:cc.Label,
        btnNext:cc.Node,
        btnAgen:cc.Node,
        nodeWin:cc.Node,
        nodeLose:cc.Node,
        starArr:[cc.Node],
    },

    onLoad () {
        cc.director.preloadScene("gameMain");
        cc.director.preloadScene("gameStart");
        this.countScore()
    },

    countScore:function(){
        var num = 0;
        for(let i = 0; i < window.passNum.length; i++)
        {
            if(window.passNum[i])
            {
                num += 1;
            }
        }

        var halve = Math.floor(100 / 3);
        var starNum = Math.floor(num * 10 / halve);
        console.log("starNum =============>>>>>>>>",starNum);
        this.saveLevelEndData(starNum);

        this.txtScore.string = (num * 10) + "%";

        if(num > 6)
        {
            window.gameLevelNum = parseInt(window.gameLevelNum) +  1;
            window.gameConfig.gameData.level = window.gameLevelNum;
            window.gameConfig.setGameConfigData("level", window.gameConfig.gameData.level);

            window.audioMgr.playGameAudio("win");
            this.nodeWin.active = true;
            this.btnNext.active = true;
            this.btnAgen.active = false;
        }
        else
        {
            window.audioMgr.playGameAudio("lose");
            this.nodeLose.active = true;
            this.btnNext.active = false;
            this.btnAgen.active = true;
        }

        this.showStarAnim(starNum);
    },

    showStarAnim:function(starNum){
        for(let i = 0; i < starNum; i++)
        {
            this.starArr[i].active = true;
        }
    },

    //储存关卡结束数据 星星颗数
    saveLevelEndData:function(levelEndData){
        var levelEndDataArr = window.gameConfig.gameData.levelEndData.split(",");
        //如果小于之前的就不改变数据
        if(levelEndDataArr[parseInt(window.gameLevelNum) - 1] < levelEndData)levelEndDataArr[parseInt(window.gameLevelNum) - 1] = levelEndData;
        var data = levelEndDataArr.join(",");
        window.gameConfig.saveGameData("levelEndData", data);
    },

    onButtonNextCallback:function(){
        window.audioMgr.playGameAudio("buttonCheck")
        cc.director.loadScene("gameMain");
    },

    onButtonAgenCallback:function(){
        window.audioMgr.playGameAudio("buttonCheck")
        cc.director.loadScene("gameMain");
    },

    onButtonReturnCallback:function(){
        window.audioMgr.playGameAudio("buttonCheck")
        cc.director.loadScene("gameStart");
    },

    onButtonHintCallback:function(){
        window.audioMgr.playGameAudio("buttonCheck");
        window.onLoadPfPopTitle(this, "功能暂未开放,敬请期待!")
    },
});
